package com.qf.service.impl;

import com.qf.dao.ProductDao;
import com.qf.dao.impl.ProductDaoImpl;
import com.qf.entity.PageBean;
import com.qf.entity.Product;
import com.qf.service.ProductService;

import java.sql.SQLException;
import java.util.List;

/**
 * @Author:YuhuaZhang
 * @Description
 * @Date:Created in 10:00 2021/11/5
 * @Modified By:
 */
public class ProductServiceImpl implements ProductService {
    @Override
    public PageBean<Product> findPage(String tid, int page, int pageSize) throws SQLException {

        ProductDao productDao = new ProductDaoImpl();
        /**
         * 查询总条数
         */
        long count = productDao.selectCountByTid(tid);

        /**
         * 查询当前页对应的商品
         */
        List<Product> list = productDao.selectProductByPage(page,pageSize,tid);

        //limit (currentPage-1)*pageSize,pageSize;

        return new PageBean<Product>(list, page, pageSize, count);
    }

    @Override
    public Product findProductByPid(String pid) throws SQLException {
        ProductDao productDao=new ProductDaoImpl();

        Product product=productDao.selectProductByPid(pid);
        return product;
    }
}
